//
//  SEGLayoutMacro.h
//  FrameworkTest
//
//  Created by 山刘 on 2018/7/21.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#if __has_include(<Commom/UIColor+SEGTheme.h>)
#import <Commom/UIColor+SEGTheme.h>
#else
#import "UIColor+SEGTheme.h"
#endif

#define SEGPicName(file) [SEGLayoutMacro segImageWithName:file]
#define SEGAutoPicName(file) [SEGLayoutMacro segAutoImageWithName:file filePath:[NSString stringWithFormat:@"%s",(__FILE__)]]
/// 设置动态颜色 (anyColor:默认颜色 darkColor:暗黑颜色)
#define SEGAppearanceColor(anyColor, darkColor) [UIColor seg_setColorWithAny:(anyColor) dark:(darkColor)]
/// 设置16进制动态颜色 (hexAnyColor:默认颜色字符串 hexDarkColor:暗黑颜色字符串)
#define SEGAppearanceHexColor(hexAnyColor, hexDarkColor) [UIColor seg_setColorWithAny:[UIColor colorWithHexString:(hexAnyColor)] dark:[UIColor colorWithHexString:(hexDarkColor)]]

typedef NS_ENUM(NSUInteger, SEGEnumEdgesForView) {
    SEGEnumEdgesForView_NO = 0, /*界面上都不存在 导航栏高度、TabBar高度*/
    SEGEnumEdgesForView_Top = 1, /*界面上只存在 导航栏高度*/
    SEGEnumEdgesForView_Bottom = 2, /*界面上只存在 TabBar高度*/
    SEGEnumEdgesForView_TopAndBottom = 3 /*界面上都存在 导航栏高度、TabBar高度*/
};

#define kLayout_0_5 0.5
#define kLayout_20 20.0
#define kLayout_44 44.0
#define kLayout_320 320.0
#define kLayout_15 15.0

#pragma mark - 设置字体大小的宏定义
#define kFont_8 [UIFont systemFontOfSize:8.0] //弱
#define kFont_9 [UIFont systemFontOfSize:9.0]
#define kFont_10 [UIFont systemFontOfSize:10.0] //弱
#define kFont_11 [UIFont systemFontOfSize:11.0]
#define kFont_12 [UIFont systemFontOfSize:12.0] //一般
#define kFont_13 [UIFont systemFontOfSize:13.0]
#define kFont_14 [UIFont systemFontOfSize:14.0]
#define kFont_15 [UIFont systemFontOfSize:15.0]
#define kFont_16 [UIFont systemFontOfSize:16.0] //重要
#define kFont_17 [UIFont systemFontOfSize:17.0]
#define kFont_18 [UIFont systemFontOfSize:18.0] //重要
#define kFont_19 [UIFont systemFontOfSize:19.0] //强调
#define kFont_20 [UIFont systemFontOfSize:20.0]
#define kFont_21 [UIFont systemFontOfSize:21.0]
#define kFont_22 [UIFont systemFontOfSize:22.0] //强调
#define kFont_26 [UIFont systemFontOfSize:26.0]
#define kFont_30 [UIFont systemFontOfSize:30.0]
#define kFont_35 [UIFont systemFontOfSize:35.0]
#define kFont_36 [UIFont systemFontOfSize:36.0]


#pragma mark - 布局类距离常用宏定义

#define kSEGBottomPadding 44

//邻里圈内容控件左边距离
#define kNeighbourTextLeftPadding 65

//缩略相片的宽度
#define IM_THEMBNAIL_PHOTO_WIDTH 90

//缩略相片的高度
#define IM_THEMBNAIL_PHOTO_HEIGHT 120

//一般用于特别强调，如咨询标题，问卷标题
#define FONT_TITLE_SIZE 20

//一般用于双行纯文字，强调,标题,如商圈
#define FONT_DOUBLE_IMPROTANT_SIZE 18

//一般用于导航条的文字按钮
#define FONT_NAVIGATION_SIZE 17

#define FONT_SIXTEEN 16

//常用字体大小，一般用于列表标题和详情正文等一级内容
#define FONT_LIST_AND_DETAIL_SIZE 15

//一般标签控制栏文字
#define FONT_SEGMENT_CONTROLLER_SIZE 14

//常用字体大小，一般用于列表摘要，详情描述等次级内容
#define FONT_BRIEF_SIZE 13

//非常用字大小，一般用于说明，注释，连接等
#define FONT_DESCRIPTION_SIZE 12

//用于控件的注释，如社区调查进度条。
#define FONT_ANNOTATION_SIZE 10

/**
 适配宽度 用UI的宽度 * kScaleWidth
 一般用于 宽度的间距适配、图片宽度的适配、文字控件宽度适配等
 */
#define kScaleWidth [[UIScreen mainScreen] bounds].size.width / 375.f
/**
 适配宽度 用UI的高度 * kScaleHeight
 一般用于 高度的间距适配
 */
#define kScaleHeight [[UIScreen mainScreen] bounds].size.height / 667.f

#pragma mark - 机型

#define kStatusbarHeight [[UIApplication sharedApplication] statusBarFrame].size.height



/**
 判断是否是iPhoneX机型
 
 @return BOOL
 */
static inline BOOL LYIsiPhoneX() {
    if (@available(iOS 11.0, *)) {
        CGFloat height = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;
        return (height > 0);
    } else {
        return NO;
    }
}

#pragma mark - 状态栏

/**
 状态栏高度
 
 @return CGFloat
 */
static inline CGFloat LYStatusBarHeight(){
    return kStatusbarHeight;
}

/**
 安全区域顶部距离 iPhoneX为44，其他为0
 */
static inline CGFloat LYSafeAreaTop() {
    return LYIsiPhoneX() ? 44.F : 0.F;
}

/**
 安全区域底部距离 iPhoneX为34，其他为0
 */
static inline CGFloat LYSafeAreaBottom(){
    return LYIsiPhoneX() ? 34.F : 0.F;
}

#pragma mark - 导航栏
/**
 导航栏高度
 
 @return CGFloat
 */
static inline CGFloat LYNavigationBarHeight(){
    return 44.F;
}

/**
 导航栏总高度:导航栏高度+状态栏高度
 
 @return CGFloat
 */
static inline CGFloat LYNavigationBarAndStatusBarHeight(){
    return LYNavigationBarHeight() + LYStatusBarHeight();
}
/**
 设置当前导航栏背景色

 @param vc 当前控制器
 @param color 当前控制器导航栏背景色
 */
static inline void LYNavigationBarTintColor(UIViewController* vc ,UIColor *color){
    if (!vc || !vc.navigationController || !vc.navigationController.navigationBar || !color) return;
    [vc.navigationController.navigationBar setBarTintColor:color];
}

#pragma mark - TabBar
/**
 导航栏总高度:导航栏高度+状态栏高度
 
 @return CGFloat
 */
static inline CGFloat LYTabBarHeight(){
    return LYIsiPhoneX() ? 83.F : 49.F;
}

/**
 导航栏总高度:导航栏高度+状态栏高度
 
 @return CGFloat
 */
static inline CGFloat LYTabHeightTotal(){
    return LYTabBarHeight();
}



#pragma mark - 获取当前屏幕宽、高

/**
 屏幕宽度

 @return CGFloat
 */
static inline CGFloat LYScreenWidth(){
    return [UIScreen mainScreen].bounds.size.width;
}

/**
 屏幕高度

 @return CGFloat
 */
static inline CGFloat LYScreenHeight(){
    return [UIScreen mainScreen].bounds.size.height;
}

#pragma mark - 获取当前屏幕宽高缩放系数
/**
 宽度缩小系数

 @return CGFloat
 */
static inline CGFloat LYScreenScaleWidth(){
    return LYScreenWidth()/375.0;
}

/**
 高度缩小系数

 @return CGFloat
 */
static inline CGFloat LYScreenScaleHeight(){
    return LYScreenHeight()/667.0;
}

/**
 广告banner适配x xs xr
 
 @return 高度
 */
static inline CGFloat LYScaleBannerHeight(){
    return (LYScreenWidth()/375.0*235);
}

#pragma mark - 获取适配后的横向、纵向距离
/**
 适配后的横向距离

 @param dis iPhone6 为基础的pt尺寸
 @return CGFloat
 */
static inline CGFloat LYDistanceV(CGFloat dis){
    return dis * LYScreenScaleWidth();
}

/**
 适配后的纵向距离

 @param dis iPhone6 为基础的pt尺寸
 @return CGFloat
 */
static inline CGFloat LYDistanceH(CGFloat dis){
    return dis * LYScreenScaleHeight();
}

/**
 渲染像素比例 缩放因子

 @return CGFloat
 */
static inline CGFloat LYScreenScale(){
    return [UIScreen mainScreen].scale;
}

/**
 创建 Size 并且进行适配
 
 @param width CGFloat
 @param height CGFloat
 @return CGSize
 */
static inline CGSize LYSizeMake(CGFloat width,CGFloat height){
    return CGSizeMake(LYDistanceV(width), LYDistanceH(height));
}

/**
 适配后的 CGSize

 @param size 这里的宽、高必须为没有进行适配的值
 @return CGSize
 */
static inline CGSize LYSize(CGSize size){
    return LYSizeMake(size.width, size.height);
}

/**
 适配后的 CGRect
 
 @param rect 这里的值必须为没有进行适配的值
 @return CGSize
 */


/**
 创建 Rect 并且进行适配

 @param x CGFloat
 @param y CGFloat
 @param w CGFloat
 @param h CGFloat
 @return CGRect
 */
static inline CGRect LYRectMake(CGFloat x , CGFloat y , CGFloat w , CGFloat h){
    return CGRectMake(LYDistanceV(x), LYDistanceH(y), LYDistanceV(w), LYDistanceH(h));
}

/**
 适配后的 CGRect
 
 @param rect 这里的值必须为没有进行适配的值
 @return CGSize
 */
static inline CGRect LYRect(CGRect rect){
    return LYRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}

/**
 创建 Point 并且进行适配

 @param x CGFloat
 @param y CGFloat
 @return CGPoint
 */
static inline CGPoint LYPointMake(CGFloat x , CGFloat y){
    return CGPointMake(LYDistanceV(x), LYDistanceH(y));
}

/**
 适配后的 CGPoint
 
 @param point 这里的值必须为没有进行适配的值
 @return CGSize
 */
static inline CGPoint LYPoint(CGPoint point){
    return LYPointMake(point.x, point.y);
}

/**
 创建 EdgeInsets 并且进行适配

 @param top CGFloat
 @param left CGFloat
 @param bottom CGFloat
 @param right CGFloat
 @return UIEdgeInsets
 */
static inline UIEdgeInsets LYEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right){
    return UIEdgeInsetsMake(LYDistanceH(top), LYDistanceV(left), LYDistanceH(bottom), LYDistanceV(right));
}

/**
 适配后的 UIEdgeInsets
 
 @param insets 这里的值必须为没有进行适配的值
 @return CGSize
 */
static inline UIEdgeInsets LYEdgeInsets(UIEdgeInsets insets){
    return LYEdgeInsetsMake(insets.top, insets.left,insets.bottom, insets.right);
}
@interface SEGLayoutMacro : NSObject
+ (NSString*)segImageWithName:(NSString*)name;
+ (UIImage *)segAutoImageWithName:(NSString*)name filePath:(NSString *)file;
@end


@interface UIView (Base)
//@property (nonatomic) CGFloat x;
//@property (nonatomic) CGFloat y;
//@property (nonatomic) CGFloat left;        ///< Shortcut for frame.origin.x.
//@property (nonatomic) CGFloat top;         ///< Shortcut for frame.origin.y
//@property (nonatomic) CGFloat right;       ///< Shortcut for frame.origin.x + frame.size.width
//@property (nonatomic) CGFloat bottom;      ///< Shortcut for frame.origin.y + frame.size.height
//@property (nonatomic) CGFloat width;       ///< Shortcut for frame.size.width.
//@property (nonatomic) CGFloat height;      ///< Shortcut for frame.size.height.
//@property (nonatomic) CGFloat centerX;     ///< Shortcut for center.x
//@property (nonatomic) CGFloat centerY;     ///< Shortcut for center.y
//@property (nonatomic) CGPoint origin;      ///< Shortcut for frame.origin.
//@property (nonatomic) CGSize  size;        ///< Shortcut for frame.size.


@property (nonatomic) CGFloat ly_x;
@property (nonatomic) CGFloat ly_y;
@property (nonatomic) CGFloat ly_left;
@property (nonatomic) CGFloat ly_top; 
@property (nonatomic) CGFloat ly_right;
@property (nonatomic) CGFloat ly_bottom;
@property (nonatomic) CGFloat ly_width;
@property (nonatomic) CGFloat ly_height;   
@property (nonatomic) CGFloat ly_centerX;
@property (nonatomic) CGFloat ly_centerY;
@property (nonatomic) CGPoint ly_origin;
@property (nonatomic) CGSize  ly_size;
@end
